export default {
  data() {
    return {
      // 设置属性
      mixinViewModuleOptions: {
        createdIsNeed: true, // 此页面是否在创建时，调用查询数据列表接口？
        activatedIsNeed: false, // 此页面是否在激活（进入）时，调用查询数据列表接口？
        getDataListURL: "", // 数据列表接口，API地址
        deleteURL: "", // 删除接口，API地址
      },
      // 默认属性
      dataForm: {}, // 查询条件
      dataList: [], // 数据列表
      pageNum: 1, // 当前页码
      pageSize: 10, // 每页数
      total: 0, // 总条数
      fixedTableHeight: null,
      isFixedTableH: false, // 是否固定表头
      onlyShowSelf: false, // 仅展示商户自身数据
    };
  },
  watch: {
    isFixedTableH: {
      handler(val) {
        if (val) {
          this.fixedTableHeight = 530;
        } else {
          this.fixedTableHeight = "";
        }
      },
    },
    deep: true,
  },
  created() {
    if (this.mixinViewModuleOptions.createdIsNeed) {
      this.query();
    }
  },
  activated() {
    if (this.mixinViewModuleOptions.activatedIsNeed) {
      this.query();
    }
  },
  mounted() {},
  computed: {},
  methods: {
    // 获取数据列表
    query() {
      //console.log(this.dataForm);
      this.$http
        .post(this.mixinViewModuleOptions.getDataListURL, {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          params: {
            ...this.dataForm,
          },
          ...this.bodyForm,
        })
        .then((res) => {
          if (res.code !== "0000") {
            this.dataList = [];
            this.total = 0;
            // return this.$message.error(res.msg)
          }
          this.dataList = res.data.list;
          this.total = res.data.total;
        })
        .catch(() => {
          // this.dataListLoading = false
        });
    },
    // // 多选
    // dataListSelectionChangeHandle (val) {
    //   this.dataListSelections = val
    // },
    // // 排序
    // dataListSortChangeHandle (data) {
    //   if (!data.order || !data.prop) {
    //     this.order = ''
    //     this.orderField = ''
    //     return false
    //   }
    //   this.order = data.order.replace(/ending$/, '')
    //   this.orderField = data.prop.replace(/([A-Z])/g, '_$1').toLowerCase()
    //   this.query()
    // },

    // 分页, 每页条数
    pageSizeChangeHandle(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.query();
    },
    // 分页, 当前页
    pageCurrentChangeHandle(val) {
      this.pageNum = val;
      this.query();
    },
    // 查询
    getDataList() {
      this.pageNum = 1;
      this.query();
    },
    // 新增 / 修改
    // addOrUpdateHandle (id) {
    //   this.addOrUpdateVisible = true
    //   this.$nextTick(() => {
    //     this.$refs.addOrUpdate.dataForm.id = id
    //     this.$refs.addOrUpdate.init()
    //   })
    // },
    // 关闭当前窗口
    // closeCurrentTab (data) {
    //   var tabName = this.$store.state.contentTabsActiveName
    //   this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
    //   if (this.$store.state.contentTabs.length <= 0) {
    //     this.$store.state.sidebarMenuActiveName = this.$store.state.contentTabsActiveName = 'home'
    //     return false
    //   }
    //   if (tabName === this.$store.state.contentTabsActiveName) {
    //     this.$router.push({ name: this.$store.state.contentTabs[this.$store.state.contentTabs.length - 1].name })
    //   }
    // },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 删除
    deleteHandle(id, delMsg) {
      //console.log(id);
      let msg = delMsg === undefined ? "确认删除吗" : delMsg;
      this.$confirm(msg, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "confirm",
        showClose: false,
        closeOnClickModal: false,
        closeOnPressEscape: false,
        type: "warning",
        center: true,
      }).then(() => {
        this.$http
          .delete(this.mixinViewModuleOptions.deleteURL, {
            params: {
              id,
            },
          })
          .then((res) => {
            if (res.code !== "0000") {
              return;
            }
            this.$message({
              message: "删除成功",
              type: "success",
              duration: 1000,
              onClose: () => {
                if (Number.isInteger((this.total - 1) / this.pageSize)) {
                  this.pageNum = (this.total - 1) / this.pageSize;
                  if (this.pageNum == 0) {
                    this.pageNum = 1;
                  }
                }
                this.query();
              },
            });
          })
          .catch(() => {});
      });
    },
  },
};
